package com.salinity.kun.model;

/**
 * 
 * @author Kuner_Rick
 * 
 *         分潮周期，单位为分钟
 *
 */

public enum Tides {
	K1(1436.04), S1(1440), P1(1443.96), MS4(1464.72), M1(1490.52), O1(1549.139), Q1(1612.08);

	private double val;

	private Tides(double val) {
		this.setVal(val);
	}

	public double getVal() {
		return val;
	}

	public double getVal(int interval) {
		return roundVal(interval);
	}

	public void setVal(double val) {
		this.val = val;
	}
	/**
	 * 获取最接近的能够被interval 整除的整数
	 * 
	 * @param interval
	 * @return
	 */
	private double roundVal(int interval) {
		if (interval <= 0)
			return val;
		long roundVal = Math.round(val);
		long modVal = roundVal % interval;
		if (modVal == 0)
			return roundVal;

		if (interval < modVal * 2) {
			return roundVal - (roundVal % interval) + interval;
		}else {
			return roundVal - (roundVal % interval);
		}
	}

}
